package com.emax.zhenghe.omsbase.modules.trans.vo;

import com.emax.trans.rpcapi.adjustmentorder.dto.AdjustmentOrderDTO;
import com.emax.trans.transfer.TransferStatusEnum;
import com.emax.zhenghe.common.enums.AdjustmentTypeEnum;
import com.emax.zhenghe.common.enums.AuditStatusEnum;
import com.emax.zhenghe.common.enums.ProjectStatusEnum;
import com.emax.zhenghe.common.util.BigDecimalUtil;
import com.emax.zhenghe.common.util.StringUtil;
import com.emax.zhenghe.rpcapi.modules.auditrecord.dto.AuditRecordDTO;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class AdjustmentOrderVO implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 业务流水号
     */
    @ApiModelProperty(value = "业务流水号")
    private ProjectStatusEnum orderNo;

    /**
     * 原业务流水号
     */
    @ApiModelProperty(value = "原业务流水号")
    private T orgOrderNo;
    /**
     * 付款名称
     */
    @ApiModelProperty(value = "付款名称")
    private String payerName;

    /**
     * 付款账户
     */
    @ApiModelProperty(value = "付款账户")
    private String payerAccount;

    /**
     * 收款名称
     */
    @ApiModelProperty(value = "收款名称")
    private String payeeName;

    /**
     * 收款账户
     */
    @ApiModelProperty(value = "收款账户")
    private String payeeAccount;

    /**
     * 调账金额(单位：分)
     */
    @ApiModelProperty(value = "调账金额(单位：分)")
    private String adjustmentAmount;

    /**
     * 调账类型 AdjustmentTypeEnum(INCREASE调增、DECREASE调减)
     */
    @ApiModelProperty(value = "调账类型")
    private String adjustmentType;

    /**
     * 调账类型 AdjustmentTypeEnum(INCREASE调增、DECREASE调减)
     */
    @ApiModelProperty(value = "调账类型名称")
    private String adjustmentTypeName;

    /**
     * 状态 AuditStatusEnum（UN_AUDIT待审核、SUCCESS审核通过、FAIL审核拒绝、CANCELED已撤销、已撤销、撤销失败）
     */
    @ApiModelProperty(value = "状态")
    private String auditStatus;

    /**
     * 状态 AuditStatusEnum（UN_AUDIT待审核、SUCCESS审核通过、FAIL审核拒绝、CANCELED已撤销、已撤销、撤销失败）
     */
    @ApiModelProperty(value = "状态名称")
    private String auditStatusName;

    /**
     * 调账交易状态TransferStatusEnum（TRANSFER_INIT初始、TRANSFER_PROCESS处理中、TRANSFER_SUCCESS调整成功、TRANSFER_FAIL调账失败）
     */
    @ApiModelProperty(value = "调账交易状态")
    private String transferStatus;

    /**
     * 调账交易状态AdjustStatusEnum（INIT初始、SEPARATING处理中、SUCCESS调整成功、FAIL调账失败）
     */
    @ApiModelProperty(value = "调账交易状态名称")
    private String transactionStatusName;


    @ApiModelProperty(value = "备注")
    private String  remark ;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 审核备注
     */
    @ApiModelProperty(value = "审核备注")
    private String auditRemark;



    @ApiModelProperty(value = "审核时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date auditTime;


    /**
     * 凭证
     */
    @ApiModelProperty(value = "凭证")
    private String credentialUrl;

    /**
     * 按钮展示：审核:AUDIT,撤销:REVOKE
     */
    private String buttonName;




    public void  build(AdjustmentOrderDTO adjdto,AuditRecordDTO auddto){
            this.orderNo = adjdto.getOrderNo();
            this.orgOrderNo = adjdto.getOrgOrderNo();
            this.payerName =  adjdto.getPayerName();
            this.payerAccount = adjdto.getPayerAccount();
            this.payeeName = adjdto.getPayeeName();
            this.payeeAccount = adjdto.getPayeeAccount();
            this.adjustmentAmount = BigDecimalUtil.changeFen2Yuan(adjdto.getAdjustmentAmount());
            this.adjustmentType = adjdto.getAdjustmentType();
            if(StringUtil.isNotEmpty(adjdto.getAdjustmentType())){
                this.adjustmentTypeName = AdjustmentTypeEnum.getMsgByCode(adjdto.getAdjustmentType());
            }
            this.auditStatus = adjdto.getAuditStatus();
           if(StringUtil.isNotEmpty(adjdto.getAuditStatus())){
              this.auditStatusName = AuditStatusEnum.getDescriptionByCode(adjdto.getAuditStatus());
           }
            this.transferStatus =adjdto.getTransferStatus();
           if(StringUtil.isNotEmpty(adjdto.getTransferStatus())){
               TransferStatusEnum  transferStatusEnum = TransferStatusEnum.getBeanByCode(adjdto.getTransferStatus());
               this.transactionStatusName = transferStatusEnum == null? "": transferStatusEnum.getDescription();
           }
            this.createTime = adjdto.getCreateTime();
            if(auddto != null){
                this.remark =auddto.getRemark();
                this.auditRemark = auddto.getAuditRemark();
                this.auditTime =  auddto.getAuditTime();
                this.credentialUrl =  auddto.getCredentialUrl();
            }
          if(StringUtil.isNotEmpty(adjdto.getAdjustmentType())
          && StringUtil.isNotEmpty(adjdto.getAuditStatus())
          && StringUtil.isNotEmpty(adjdto.getTransferStatus())
          ){
              //默认待审核展示审核按钮
              if(AuditStatusEnum.UN_AUDIT.codeEquals(adjdto.getAuditStatus())){
                  this.buttonName = "AUDIT";
              }
              //类型调增和审核成功和交易状态是成功展示撤销按钮
              if(AdjustmentTypeEnum.INCREASE.codeEquals(adjdto.getAdjustmentType())
                &&  TransferStatusEnum.TRANSFER_SUCCESS.codeEquals(adjdto.getTransferStatus())
                && AuditStatusEnum.SUCCESS.codeEquals(adjdto.getAuditStatus())
              ){
                  this.buttonName = "REVOKE";
              }

          }

    }
}
